<?php

namespace Bean\Flow\GenericFlow;

abstract class Item extends \Bean\Flow\Item {

	public abstract function getUser();
	
	public abstract function getPublicationTime();
	
	public abstract function getItemId();
	
	public abstract function getFlow();

	public function isLikable( \Bean\User $user = null ) {
		return false;
	}
	
	public function isCommentable( \Bean\User $user = null ) {
		return false;
	}
	
	public function isDeletable( \Bean\User $user = null ) {
		return false;
	}
	
	public function addComment( $message ) {
		throw new \Exception( 'Not implemented' );
	}
	
	public function addLink( $message ) {
		throw new \Exception( 'Not implemented' );
	}
	
	public function like( \Bean\User $user = null ) {
		throw new \Exception( 'Not implemented' );
	}
	
	public function unlike( \Bean\User $user = null ) {
		throw new \Exception( 'Not implemented' );
	}
	
	public function delete() {
		throw new \Exception( 'Not implemented' );
	}
	
	public function getLinks() {
		return array();
	}
	
	public function getLikes() {
		return null;
	}
	
	public function getComments() {
		return array();
	}

	public function getGenericId() {
		preg_match( '/Bean\\\Flow\\\([^\\\]+)Flow/', get_class($this), $match );
		return $match[1] . ':' . $this->getItemId(); 
	}
	
	public static function get( $genericId, \Bean\Flow\GenericFlow $flow = null ) {
		$pos = strpos($genericId, ':');
		$class = '\Bean\Flow\\' . substr($genericId, 0, $pos) . 'Flow\Item';
		return $class::get( substr($genericId, $pos+1), $flow );
	}
	
	public function getView() {
		return 'Widget/Flow/GenericFlow/Item';
	}
	
	public function equals( \Bean\Flow\Item $item ) {
		return $item instanceof Item 
			&& ($item->getGenericId() == $this->getGenericId());
	}
}
